package Teach;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.01.18.10.17
 */
public class Pj1 {
    public static void main(String[] args) {
        //读取文件
        String f = "D:\\java\\log\\20201222-type.txt";
        try {
            FileInputStream fis = new FileInputStream(f);
            //System.out.println(new String(fis.readAllBytes(),"utf-8"));

            byte[] buf = new byte[1024];
            int len = 0;
            while((len = fis.read(buf))>0) {
                System.out.println(new String(buf,"utf-8"));
            }
            fis.close();
        }catch(Exception e) {

        }
    }
    public static void write(String str) {
        try {
            //建立文件输出流，用来写入内容，true,追加模式
            FileOutputStream fos = new FileOutputStream("c:/u.txt",true);
            fos.write(String.format("hello world 中文效果(%1$tF %1$tT)\r\n", System.currentTimeMillis()).getBytes());
            fos.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
